extends Sprite

onready var _slider = get_node("button/slider")
onready var _sizeW = get_node("button").rect_size.x
var _pressed = false

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

func _on_button_gui_input(event):
	if event is InputEventMouseButton:
		if event.pressed:
			setValue(event.position.x / _sizeW)
			_pressed = true
		elif !event.pressed:
			_pressed = false
	elif event is InputEventMouseMotion && _pressed:
		#var size = get_rect().size
		setValue(event.position.x / _sizeW)
		pass
	pass # Replace with function body.

func setValue(v : float):
	if v <= 0.0:
		v = 0
	if v >= 1.0:
		v = 1.0
	_slider.position.x = _sizeW * v
	pass
